//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.apache.hadoop.hive.serde2.objectinspector.primitive;

import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;

public class WritableLongObjectInspector extends AbstractPrimitiveWritableObjectInspector implements SettableLongObjectInspector {
    WritableLongObjectInspector() {
        super(TypeInfoFactory.longTypeInfo);
    }

    @Override
    public long get(Object o) {

        if (o instanceof LongWritable) {
            return ((LongWritable) o).get();
        } else if (o instanceof Text) {
            return Long.parseLong(o.toString());
        }
        return -1;
    }

    @Override
    public Object copyObject(Object o) {
        return o == null ? null : new LongWritable(((LongWritable) o).get());
    }

    @Override
    public Object getPrimitiveJavaObject(Object o) {
        return o == null ? null : ((LongWritable) o).get();
    }

    @Override
    public Object create(long value) {
        return new LongWritable(value);
    }

    @Override
    public Object set(Object o, long value) {
        ((LongWritable) o).set(value);
        return o;
    }
}
